<?php

require_once 'include/language_manager.inc.php';
Language_Manager::getInstance();

$meta["title"] = L::meta_master_title;
$meta["description"] = L::meta_master_description;
$meta["keywords"] = L::meta_master_keywords;

require "include/template_manager.inc.php";
$myTemplate = new Template_Manager("master", null,true,2,$meta);

$myTemplate->setBodyContentString("nav_message", L::nav_message);
$myTemplate->setBodyContentString("nav_home", L::nav_home);
$myTemplate->setBodyContentString("nav_page", L::messages_master_nav_page);

$query = "select `c`.`id` AS `id`,`c`.`nome` AS `nome`,`c`.`nome_en` AS `nome_en`,concat(`u`.`nome`,' ',`u`.`cognome`) AS `professore`,`c`.`ore` AS `ore` from (`professori` `u` join `corsi` `c`) where (`c`.`id_professore` = `u`.`id`)";
if ($data = DB_Manager::getInstance()->query($query)) {
    $sum = 0;
    while ($row = $data->fetch_array(MYSQLI_ASSOC)) {
        $title = "";
        $prefix = "/";
        if (getLanguage() == "it") {
            $title = $row['nome'];
        } else {
            $title = $row['nome_en'];
            $prefix = "/en/";
        }
        $myTemplate->setBodyContentString("titolo", $title);
        $myTemplate->setBodyContentString("link_nome", Config::$site_name.$prefix.'master/'.$title.'/');
        $myTemplate->setBodyContentString("ore", $row['ore']);
        $sum+=(int) $row['ore'];
    }
    $myTemplate->setBodyContentString("sum",  $sum);
}
$myTemplate->setCanonicalUrl($prefix."master/");
$myTemplate->setBodyContentString("h3_title", L::messages_master_h3_title);
$myTemplate->setBodyContentString("teachings", L::messages_master_teachings);
$myTemplate->setBodyContentString("master_description", L::messages_master_description);
$myTemplate->setBodyContentString("click_details", L::messages_master_click_details);
$myTemplate->setBodyContentString("total_credits", L::messages_master_total_credits);
